package appconfig

import (
	"fmt"
	"github.com/spf13/viper"
	"github.com/zeromicro/go-zero/core/logx"
)

type AppConfig struct {
	Mysql
	Redis
	SendSms
	QiNiuYun
}
type Mysql struct {
	Host     string
	Port     int
	User     string
	Password string
	Database string
}
type Redis struct {
	Host     string
	Port     int
	Password string
}
type SendSms struct {
	AccessKeyId     string
	AccessKeySecret string
	Endpoint        string
}
type QiNiuYun struct {
	AccessKey string
	SecretKey string
	Bucket    string
	Url       string
}

var Appconf AppConfig

func Init() {
	var err error
	viper.SetConfigFile("appconfig/dev.yaml")
	if err = viper.ReadInConfig(); err != nil {
		logx.Info("读取配置文件失败" + err.Error())
	}
	if err = viper.Unmarshal(&Appconf); err != nil {
		logx.Info("解析配置文件失败" + err.Error())
	}
	fmt.Println("动态配置数据文件成功")
}
